﻿using UnityEngine;
using System.Collections;

public class TrunkSpawner : MonoBehaviour {

	public GameObject TrunkObject;
	public float spawnTimer;
	public float initialSpawnTimer = 0.3f;
	public float spacer;
	public float timeToDestroy = 20f;

	// Use this for initialization
	void Start () {
		this.spawnTimer = this.initialSpawnTimer;
		this.spacer = this.TrunkObject.transform.localScale.y * 2;
		this.SpawnTrunk ();
	}
	
	// Update is called once per frame
	void Update () {
		this.spawnTimer -= Time.deltaTime;
		if (this.spawnTimer < 0) {
			this.SpawnTrunk();
			this.resetTimer();
		}
	}

	private void SpawnTrunk(){
		Instantiate (this.TrunkObject, new Vector3 (0f, 1f, this.spacer), Quaternion.Euler (90f, 0f, 0f));
		this.spacer += this.TrunkObject.transform.localScale.y * 2;
	}

	private void resetTimer(){
		this.spawnTimer = this.initialSpawnTimer;
	}

}
